/*

	This is the master do file for the New Haven Public Schools portion of the 
	codebase of	Smart Matching Platforms and Heterogenous Beliefs in Centralized 
	School Choice by Feliper Arteaga, Adam J. Kapor, Christopher A. Neilson, and
	Seth D. Zimmerman. From here, you can run all relevant do files and create
	the output that is reported in the paper.
	
*/

/// set the version
version 16.1

/// Be sure you are in the directory where master.do is located
cap confirm file "./master.do"
if _rc != 0 {
	cap cd ./new_haven
	if _rc != 0{
		cap cd ./code/new_haven
		if _rc != 0 {
			di "You are in the wrong directory."
			break
		}
	}
}

/// Set a random seed
set seed 294823

/// Set directories
confirm file master.do
global code "`c(pwd)'"
cd ../..
global main "`c(pwd)'"
global raw "$main/data/raw_data" // All raw data is stored in this folder
cd "$code"
global user "`c(username)'"

* Input data
global geocodes "$raw/geocodes"
global smartchoice "$raw/smartChoiceBackup"
global smartchoice_final2019 "$smartchoice/data-2019-04-19"
global smartchoice_final2020 "$smartchoice/data-2020-03-03"
global preprocessed "$raw/preprocessed"
global preprocessed_smartchoice "$preprocessed/smartchoice"
global sim "$preprocessed/2020_sim_intervention"	
foreach file in "email_logs" "logins" "randomizations" "sim_use" { 
	global `file' "$sim/`file'.csv"	
}
global email_survey2020 "$preprocessed/2020_survey_email/email-survey2020-clean.csv"
global email_survey2019 "$preprocessed/2019_survey_email/email_survey2019_clean.csv"

* Intermediate data folder
global int "$main/data/intermediate_data"

* Figures, tables, and notes
global figures "$main/output/figures"
global tables "$main/output/tables"
global notes "$main/output/notes"

* Outcomes lists used in analysis 
global outcomes_first_stage = "email_received warnings_email login_count"
global outcomes_sec_stage = ///
	"modify_ever lengthen_app_ever new_insert_ever " + ///
	" new_append_ever change_school_ever shorten_app_ever " + ///
	"risk_real_diff risk_sim_diff"
global outcomes_sec_stage_figure = ///
	"modify_ever lengthen_app_ever risk_real_diff"
global outcomes_sec_stage_final = ///
	"modify_final lengthen_app_final new_insert_final " + ///
	" new_append_final change_school_final shorten_app_final"
global outcomes_placement = "placed_dayof1 placed_other unplaced"
global outcomes_sim_use = "$outcomes_first_stage any_sim"

/// Now we run the do files

cd "$code/clean"

* Data build
do 01_make_data.do 

cd "$code/analysis"

* Balance table
do 01_balance_table.do

* Descriptives table
do 02_sample_descriptives.do

* Regression table
do 03_regression_tables.do

* Treatment balance and outcomes plots
do 04_did_plots_nolines.do

* Simulated risk plot
do 05_risk_binscatters.do